package com.kang.controller;

import com.kang.service.ShoppingService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author 吃三明治派对中的康康
 * @Date 2022/4/30 11:26
 * @Version 1.0
 */
@Controller
public class HeaderController {

    @Autowired
    ShoppingService shoppingService;

    @RequestMapping("/header")
    public String toHeader(Model model){
        model.addAttribute("shoppingNumModel",shoppingService.searchAllOrder().size());
        return "header";
    }

    @SneakyThrows
    @GetMapping("/search")
    public void search(String searchMessage, HttpServletRequest request, HttpServletResponse response){

        String url = "http://localhost:8080/goodsList/"+searchMessage+"/1";
        response.sendRedirect(url);

    }
}
